/**
 * 
 */
package com.dalonedrow.module.chivalrysorcery.systems;

import com.dalonedrow.engine.systems.base.Diceroller;
import com.dalonedrow.module.chivalrysorcery.constants.ChivalrySorceryConstants;
import com.dalonedrow.module.chivalrysorcery.rpg.ChivSorcCharacter;
import com.dalonedrow.pooled.PooledStringBuilder;
import com.dalonedrow.pooled.StringBuilderPool;

/**
 * @author Donald
 */
public final class ClassCreationWizard {
	/** 
	 * the one and only instance of the <code>ClassCreationWizard</code> class. 
	 */
	private static ClassCreationWizard	instance;
	/**
	 * Gives access to the singleton instance of {@link ClassCreationWizard}.
	 * @return {@link ClassCreationWizard}
	 */
	public static ClassCreationWizard getInstance() {
		if (ClassCreationWizard.instance == null) {
			ClassCreationWizard.instance = new ClassCreationWizard();
		}
		return ClassCreationWizard.instance;
	}
	/** hidden constructor. */
	private ClassCreationWizard() { }
	/**
	 * Generates a random chivalric vocation.
	 * @param character the {@link ChivSorcCharacter}
	 */
	private void assignRandomChivalricVocation(
			final ChivSorcCharacter character) {
		int vocation;
		final int c = 100;
		final int k0 = 6, k1 = 12, k2 = 18, k3 = 24, k4 = 30;
		final int k5 = 36, k6 = 42, k7 = 48, k8 = 54;
		final int k9 = 60, k10 = 66, k11 = 72, b12 = 78;
		final int b13 = 84, b14 = 89, b15 = 94, b16 = 98;
		int roll = Diceroller.getInstance().rolldX(c);
		if (roll <= k0) {
			vocation = ChivalrySorceryConstants.VOC_CHIV_00_KNIGHT_INT_SFMH_1;
		} else if (roll > k0 && roll <= k1) {
			vocation = ChivalrySorceryConstants.VOC_CHIV_01_KNIGHT_INT_SFMH_2;
		} else if (roll > k1 && roll <= k2) {
			vocation = ChivalrySorceryConstants.VOC_CHIV_02_KNIGHT_INT_SFMH_3;
		} else if (roll > k2 && roll <= k3) {
			vocation = ChivalrySorceryConstants.VOC_CHIV_03_KNIGHT_INT_LFMH_4;
		} else if (roll > k3 && roll <= k4) {
			vocation = ChivalrySorceryConstants.VOC_CHIV_04_KNIGHT_INT_LFMH_5;
		} else if (roll > k4 && roll <= k5) {
			vocation = ChivalrySorceryConstants.VOC_CHIV_05_KNIGHT_INT_CASTLE_1;
		} else if (roll > k5 && roll <= k6) {
			vocation = ChivalrySorceryConstants.VOC_CHIV_06_KNIGHT_FRT_SFMH_1;
		} else if (roll > k6 && roll <= k7) {
			vocation = ChivalrySorceryConstants.VOC_CHIV_07_KNIGHT_FRT_SFMH_2;
		} else if (roll > k7 && roll <= k8) {
			vocation = ChivalrySorceryConstants.VOC_CHIV_08_KNIGHT_FRT_LFMH_3;
		} else if (roll > k8 && roll <= k9) {
			vocation = ChivalrySorceryConstants.VOC_CHIV_09_KNIGHT_FRT_SK_4;
		} else if (roll > k9 && roll <= k10) {
			vocation = ChivalrySorceryConstants.VOC_CHIV_10_KNIGHT_FRT_SK_5;
		} else if (roll > k10 && roll <= k11) {
			vocation = ChivalrySorceryConstants.VOC_CHIV_11_KNIGHT_INT_CASTLE_1A;
		} else if (roll > k11 && roll <= b12) {
			vocation = ChivalrySorceryConstants.VOC_CHIV_12_BANNERETTE_INT_CASTLE_1A;
		} else if (roll > b12 && roll <= b13) {
			vocation = ChivalrySorceryConstants.VOC_CHIV_13_BANNERETTE_INT_CASTLE_1B;
		} else if (roll > b13 && roll <= b14) {
			vocation = ChivalrySorceryConstants.VOC_CHIV_14_BARON_INT_CASTLE_1C;
		} else if (roll > b14 && roll <= b15) {
			vocation = ChivalrySorceryConstants.VOC_CHIV_15_BARON_INT_CASTLE_1D;
		} else if (roll > b15 && roll <= b16) {
			vocation = ChivalrySorceryConstants.VOC_CHIV_16_BARON_INT_CASTLE_1E;
		} else {
			vocation = ChivalrySorceryConstants.VOC_CHIV_17_BARON_INT_CASTLE_1F;
		}
		character.setFatherVocation(vocation);
		character.setFatherVocationRank(
				ChivalrySorceryConstants.EMPLOY_RANK_JOURNEYMAN);
	}
	/**
	 * Generates a random family status for a character.
	 * @param character the {@link ChivSorcCharacter}
	 */
	private void assignRandomFamilyStatus(
			final ChivSorcCharacter character) {
		int rank = ChivalrySorceryConstants.FAMILY_STATUS_00_BLACK_SHEEP;
		final int c = 100;
		final int bad = 33, neutral = 66;
		int roll = Diceroller.getInstance().rolldX(c);
		// if the character is an unacknowledged bastard, check to see
		// if they are a black sheep
		boolean doRoll = true;
		if (character.getSiblingRank()
				== ChivalrySorceryConstants.SIBLINGS_BASTARD_UNACKNOWLEDGED) {
			// get father's social class
			int social;
			final int serf = 10, yeoman = 40, townsman = 60, guildsman = 80;
			final int chivalric = 95, noble = 99;
			if (character.getBirthAspect()
				== ChivalrySorceryConstants.ASPECT_00_AUSPICIOUS) {
				roll += 10;
			} else if (character.getBirthAspect()
				== ChivalrySorceryConstants.ASPECT_02_INAUSPICIOUS) {
				roll -= 10;
			}
			if (roll <= serf) {
				social = ChivalrySorceryConstants.BIRTH_CLASS_00_SERF;
			} else if (roll > serf && roll <= yeoman) {
				social = ChivalrySorceryConstants.BIRTH_CLASS_01_YEOMAN;
			} else if (roll > yeoman && roll <= townsman) {
				social = ChivalrySorceryConstants.BIRTH_CLASS_02_TOWNSMAN;
			} else if (roll > townsman && roll <= guildsman) {
				social = ChivalrySorceryConstants.BIRTH_CLASS_03_GUILDSMAN;
			} else if (roll > guildsman && roll <= chivalric) {
				social = ChivalrySorceryConstants.BIRTH_CLASS_04_CHIVALRIC;
			} else if (roll > chivalric && roll <= noble) {
				social = ChivalrySorceryConstants.BIRTH_CLASS_05_NOBLE;
			} else {
				social = ChivalrySorceryConstants.BIRTH_CLASS_06_ROYAL;
			}
			if (social < character.getFatherSocialClass()) {
				// character's father is lower rank than mother - BLACK SHEEP!
				rank = ChivalrySorceryConstants.FAMILY_STATUS_00_BLACK_SHEEP;
				doRoll = false;
			} else {
				// father is same or higher class - roll to see status
				roll = Diceroller.getInstance().rolldX(c);
			}
		}
		if (doRoll) {
			if (character.getBirthAspect()
				== ChivalrySorceryConstants.ASPECT_00_AUSPICIOUS) {
				roll += 25;
			} else if (character.getBirthAspect()
				== ChivalrySorceryConstants.ASPECT_01_NEUTRAL) {
				roll += 10;
			} else {
				roll -= 5;
			}
			if (roll <= bad) {
				rank = ChivalrySorceryConstants.FAMILY_STATUS_00_BLACK_SHEEP;
			} else if (roll > bad && roll <= neutral) {
				rank = ChivalrySorceryConstants.FAMILY_STATUS_01_CREDIT_TO_FAMILY;
			} else {
				rank = ChivalrySorceryConstants.FAMILY_STATUS_02_FAVORED_CHILD;
			}
		}
		character.setFamilyStatus(rank);
	}
	/**
	 * Generates a random guildsman vocation.
	 * @param character the {@link ChivSorcCharacter}
	 */
	private void assignRandomGuildsmanVocation(
			final ChivSorcCharacter character) {
		int voc = 0, rank = 0;
		final int c = 100;
		final int jour = 60, mast = 76, synd = 79, gm = 80;
		int roll = Diceroller.getInstance().rolldX(c);
		// get guild rank
		boolean done = false;
		while (!done) {
			if (roll <= jour) {
				rank = ChivalrySorceryConstants.EMPLOY_RANK_JOURNEYMAN;
				done = true;
			} else if (roll > jour && roll <= mast) {
				rank = ChivalrySorceryConstants.EMPLOY_RANK_MASTER;
				done = true;
			} else if (roll > mast && roll <= synd) {
				rank = ChivalrySorceryConstants.EMPLOY_RANK_GUILD_SYNDIC;
				done = true;
			} else if (roll > synd && roll <= gm) {
				rank = ChivalrySorceryConstants.EMPLOY_RANK_GUILDMASTER;
				done = true;
			} else {
				roll = Diceroller.getInstance().rolldX(c);
			}
		}
		// now check guild position
		done = false;
		final int musi = 3, danc = 6, jong = 10, troub = 15, act = 17;
		final int sculpt = 18, paint = 19, poet = 20, cabinet = 21, chef = 23;
		final int found = 24, weap = 25, arm = 26, ship = 27, cord = 28;
		final int sail = 29, captown = 30, capt = 31, pil = 32, mate = 33;
		final int shipcarp = 34, shipcook = 35, sailor = 36, build = 37;
		final int stone = 39, brick = 41, carp = 43, wool = 44, weav = 46;
		final int dyer = 47, tail = 48, tann = 49, perf = 50, glas = 51;
		final int glaz = 52, jew = 53, gold = 54, silv = 55, jewcut = 56;
		final int bank = 57, monlen = 58, monch = 59, pot = 60, merch = 61;
		final int merchadv = 63, beg = 64, thi = 65, mileng = 66, captkt = 67;
		final int kte = 68, squ = 69, sgt = 70, lng = 71, hvyx = 72, ltx = 73;
		final int maa = 74, dr = 75, barb = 76, apo = 77, mag = 79, shm = 80;
		final int alc = 81, med = 82, mech = 83, ast = 84, div = 85, hex = 86;
		final int conj = 87, ench = 88, necr = 89, thau = 90, cabb = 91;
		final int ling = 92, num = 93, phil = 94, sch = 95, sag = 96, scr = 98;
		final int pap = 99;
		while (!done) {
			roll = Diceroller.getInstance().rolldX(c);
			if (roll <= musi) {
				voc = ChivalrySorceryConstants.VOC_GUILD_00_MUSICIAN;
				done = true;
			} else if (roll > musi && roll <= danc) {
				voc = ChivalrySorceryConstants.VOC_GUILD_01_DANCER;
				done = true;
			} else if (roll > danc && roll <= jong) {
				voc = ChivalrySorceryConstants.VOC_GUILD_02_JONGULEUR;
				done = true;
			} else if (roll > jong && roll <= troub) {
				voc = ChivalrySorceryConstants.VOC_GUILD_03_TROUBADOUR;
				done = true;
			} else if (roll > troub && roll <= act) {
				voc = ChivalrySorceryConstants.VOC_GUILD_04_ACTOR;
				done = true;
			} else if (roll > act && roll <= sculpt) {
				voc = ChivalrySorceryConstants.VOC_GUILD_05_SCULPTOR;
				done = true;
			} else if (roll > sculpt && roll <= paint) {
				voc = ChivalrySorceryConstants.VOC_GUILD_06_PAINTER;
				done = true;
			} else if (roll > paint && roll <= poet) {
				voc = ChivalrySorceryConstants.VOC_GUILD_07_BARD;
				done = true;
			} else if (roll > poet && roll <= cabinet) {
				voc = ChivalrySorceryConstants.VOC_GUILD_08_CABINETMAKER;
				done = true;
			} else if (roll > cabinet && roll <= chef) {
				voc = ChivalrySorceryConstants.VOC_GUILD_09_CHEF;
				done = true;
			} else if (roll > chef && roll <= found) {
				voc = ChivalrySorceryConstants.VOC_GUILD_10_FOUNDRYMAN;
				done = true;
			} else if (roll > found && roll <= weap) {
				voc = ChivalrySorceryConstants.VOC_GUILD_11_WEAPONSMITH_MAGE;
				done = true;
			} else if (roll > weap && roll <= arm) {
				voc = ChivalrySorceryConstants.VOC_GUILD_12_ARMOURER;
				done = true;
			} else if (roll > arm && roll <= ship) {
				voc = ChivalrySorceryConstants.VOC_GUILD_13_SHIPBUILDER;
				done = true;
			} else if (roll > ship
					&& roll <= cord
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_GUILDMASTER) {
				voc = ChivalrySorceryConstants.VOC_GUILD_14_CORDAGE_MAKER;
				done = true;
			} else if (roll > cord
					&& roll <= sail
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_GUILDMASTER) {
				voc = ChivalrySorceryConstants.VOC_GUILD_15_SAILMAKER;
				done = true;
			} else if (roll > sail
					&& roll <= captown
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_JOURNEYMAN) {
				voc = ChivalrySorceryConstants.VOC_GUILD_16_CAPTAIN_OWNER;
				done = true;
			} else if (roll > captown
					&& roll <= capt
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_JOURNEYMAN) {
				voc = ChivalrySorceryConstants.VOC_GUILD_17_CAPTAIN;
				done = true;
			} else if (roll > capt && roll <= pil) {
				voc = ChivalrySorceryConstants.VOC_GUILD_18_PILOT;
				done = true;
			} else if (roll > pil
					&& roll <= mate
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_GUILDMASTER) {
				voc = ChivalrySorceryConstants.VOC_GUILD_19_MATE;
				done = true;
			} else if (roll > mate
					&& roll <= shipcarp
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_GUILDMASTER) {
				voc = ChivalrySorceryConstants.VOC_GUILD_20_SHIP_CARPENTER;
				done = true;
			} else if (roll > shipcarp
					&& roll <= shipcook
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_GUILDMASTER) {
				voc = ChivalrySorceryConstants.VOC_GUILD_21_SHIP_COOK;
				done = true;
			} else if (roll > shipcook
					&& roll <= sailor
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_GUILDMASTER) {
				voc = ChivalrySorceryConstants.VOC_GUILD_22_SAILOR;
				done = true;
			} else if (roll > sailor && roll <= build) {
				voc = ChivalrySorceryConstants.VOC_GUILD_23_ARCHITECT;
				done = true;
			} else if (roll > build && roll <= stone) {
				voc = ChivalrySorceryConstants.VOC_GUILD_24_STONEMASON;
				done = true;
			} else if (roll > stone && roll <= brick) {
				voc = ChivalrySorceryConstants.VOC_GUILD_25_BRICKMASON;
				done = true;
			} else if (roll > brick && roll <= carp) {
				voc = ChivalrySorceryConstants.VOC_GUILD_26_CARPENTER;
				done = true;
			} else if (roll > carp && roll <= wool) {
				voc = ChivalrySorceryConstants.VOC_GUILD_27_WOOL_MERCHANT;
				done = true;
			} else if (roll > wool && roll <= weav) {
				voc = ChivalrySorceryConstants.VOC_GUILD_28_WEAVER;
				done = true;
			} else if (roll > weav && roll <= dyer) {
				voc = ChivalrySorceryConstants.VOC_GUILD_29_DYER;
				done = true;
			} else if (roll > dyer && roll <= tail) {
				voc = ChivalrySorceryConstants.VOC_GUILD_30_TAILOR;
				done = true;
			} else if (roll > tail && roll <= tann) {
				voc = ChivalrySorceryConstants.VOC_GUILD_31_TANNER;
				done = true;
			} else if (roll > tann && roll <= perf) {
				voc = ChivalrySorceryConstants.VOC_GUILD_32_PERFUMER;
				done = true;
			} else if (roll > perf && roll <= glas) {
				voc = ChivalrySorceryConstants.VOC_GUILD_33_GLASSBLOWER;
				done = true;
			} else if (roll > glas && roll <= glaz) {
				voc = ChivalrySorceryConstants.VOC_GUILD_34_GLAZIER;
				done = true;
			} else if (roll > glaz && roll <= jew) {
				voc = ChivalrySorceryConstants.VOC_GUILD_35_JEWEL_SMITH_MAGE;
				done = true;
			} else if (roll > jew && roll <= gold) {
				voc = ChivalrySorceryConstants.VOC_GUILD_36_GOLDSMITH;
				done = true;
			} else if (roll > gold && roll <= silv) {
				voc = ChivalrySorceryConstants.VOC_GUILD_37_SILVERSMITH;
				done = true;
			} else if (roll > silv && roll <= jewcut) {
				voc = ChivalrySorceryConstants.VOC_GUILD_38_JEWEL_CUTTER;
				done = true;
			} else if (roll > jewcut && roll <= bank) {
				voc = ChivalrySorceryConstants.VOC_GUILD_39_BANKER;
				done = true;
			} else if (roll > bank
					&& roll <= monlen
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_GUILDMASTER) {
				voc = ChivalrySorceryConstants.VOC_GUILD_40_MONEYLENDER;
				done = true;
			} else if (roll > monlen && roll <= monch) {
				voc = ChivalrySorceryConstants.VOC_GUILD_41_MONEYCHANGER;
				done = true;
			} else if (roll > monch && roll <= pot) {
				voc = ChivalrySorceryConstants.VOC_GUILD_42_POTTER;
				done = true;
			} else if (roll > pot && roll <= merch) {
				voc = ChivalrySorceryConstants.VOC_GUILD_43_MERCHANT;
				done = true;
			} else if (roll > merch && roll <= merchadv) {
				voc = ChivalrySorceryConstants.VOC_GUILD_44_MERCHANT_ADVENTURER;
				done = true;
			} else if (roll > merchadv && roll <= beg) {
				voc = ChivalrySorceryConstants.VOC_GUILD_45_BEGGAR;
				done = true;
			} else if (roll > beg && roll <= thi) {
				voc = ChivalrySorceryConstants.VOC_GUILD_46_THIEF;
				done = true;
			} else if (roll > thi && roll <= mileng) {
				voc = ChivalrySorceryConstants.VOC_GUILD_47_MILITARY_ENGINEER;
				done = true;
			} else if (roll > mileng
					&& roll <= captkt
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_JOURNEYMAN) {
				voc = ChivalrySorceryConstants.VOC_GUILD_48_KNIGHT_CAPTAIN;
				done = true;
			} else if (roll > captkt
					&& roll <= kte
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_JOURNEYMAN) {
				voc = ChivalrySorceryConstants.VOC_GUILD_49_KNIGHT_ERRANT;
				done = true;
			} else if (roll > kte
					&& roll <= squ
					&& rank == ChivalrySorceryConstants.EMPLOY_RANK_JOURNEYMAN) {
				voc = ChivalrySorceryConstants.VOC_GUILD_50_SQUIRE_AT_ARMS;
				done = true;
			} else if (roll > squ
					&& roll <= sgt
					&& rank == ChivalrySorceryConstants.EMPLOY_RANK_JOURNEYMAN) {
				voc = ChivalrySorceryConstants.VOC_GUILD_51_SERGEANT_AT_ARMS;
				done = true;
			} else if (roll > sgt
					&& roll <= lng
					&& rank == ChivalrySorceryConstants.EMPLOY_RANK_JOURNEYMAN) {
				voc = ChivalrySorceryConstants.VOC_GUILD_52_LONGBOWMAN;
				done = true;
			} else if (roll > lng
					&& roll <= hvyx
					&& rank == ChivalrySorceryConstants.EMPLOY_RANK_JOURNEYMAN) {
				voc = ChivalrySorceryConstants.VOC_GUILD_53_HEAVY_CROSSBOWMAN;
				done = true;
			} else if (roll > hvyx
					&& roll <= ltx
					&& rank == ChivalrySorceryConstants.EMPLOY_RANK_JOURNEYMAN) {
				voc = ChivalrySorceryConstants.VOC_GUILD_54_LIGHT_CROSSBOWMAN;
				done = true;
			} else if (roll > ltx
					&& roll <= maa
					&& rank == ChivalrySorceryConstants.EMPLOY_RANK_JOURNEYMAN) {
				voc = ChivalrySorceryConstants.VOC_GUILD_55_MAN_AT_ARMS;
				done = true;
			} else if (roll > maa && roll <= dr) {
				voc = ChivalrySorceryConstants.VOC_GUILD_56_PHYSICIAN;
				done = true;
			} else if (roll > dr
					&& roll <= barb
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_GUILDMASTER) {
				voc = ChivalrySorceryConstants.VOC_GUILD_57_BARBER;
				done = true;
			} else if (roll > barb
					&& roll <= apo
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_GUILDMASTER) {
				voc = ChivalrySorceryConstants.VOC_GUILD_58_APOTHECARY;
				done = true;
			} else if (roll > apo
					&& roll <= mag
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_GUILDMASTER) {
				voc = ChivalrySorceryConstants.VOC_GUILD_59_MAGE;
				done = true;
			} else if (roll > mag
					&& roll <= shm
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_GUILDMASTER) {
				voc = ChivalrySorceryConstants.VOC_GUILD_60_SHAMAN;
				done = true;
			} else if (roll > shm && roll <= alc) {
				voc = ChivalrySorceryConstants.VOC_GUILD_61_ALCHEMIST;
				done = true;
			} else if (roll > alc
					&& roll <= med
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_GUILDMASTER) {
				voc = ChivalrySorceryConstants.VOC_GUILD_62_MEDIUM;
				done = true;
			} else if (roll > med
					&& roll <= mech
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_GUILDMASTER) {
				voc = ChivalrySorceryConstants.VOC_GUILD_63_MECHANICIAN;
				done = true;
			} else if (roll > mech && roll <= ast) {
				voc = ChivalrySorceryConstants.VOC_GUILD_64_ASTROLOGER;
				done = true;
			} else if (roll > ast
					&& roll <= div
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_GUILDMASTER) {
				voc = ChivalrySorceryConstants.VOC_GUILD_65_DIVINER;
				done = true;
			} else if (roll > div && roll <= hex) {
				voc = ChivalrySorceryConstants.VOC_GUILD_66_WITCH;
				done = true;
			} else if (roll > hex && roll <= conj) {
				voc = ChivalrySorceryConstants.VOC_GUILD_67_CONJURER;
				done = true;
			} else if (roll > conj && roll <= ench) {
				voc = ChivalrySorceryConstants.VOC_GUILD_68_ENCHANTER;
				done = true;
			} else if (roll > ench
					&& roll <= necr
					&& rank != ChivalrySorceryConstants.EMPLOY_RANK_GUILDMASTER) {
				voc = ChivalrySorceryConstants.VOC_GUILD_69_NECROMANCER;
				done = true;
			} else if (roll > necr && roll <= thau) {
				voc = ChivalrySorceryConstants.VOC_GUILD_70_THAUMATURGE;
				done = true;
			} else if (roll > thau && roll <= cabb) {
				voc = ChivalrySorceryConstants.VOC_GUILD_71_CABBALIST;
				done = true;
			} else if (roll > cabb && roll <= ling) {
				voc = ChivalrySorceryConstants.VOC_GUILD_72_LINGUICIAN;
				done = true;
			} else if (roll > ling && roll <= num) {
				voc = ChivalrySorceryConstants.VOC_GUILD_73_NUMEROLOGIST;
				done = true;
			} else if (roll > num && roll <= phil) {
				voc = ChivalrySorceryConstants.VOC_GUILD_74_PHILOSOPHER;
				done = true;
			} else if (roll > phil && roll <= sch) {
				voc = ChivalrySorceryConstants.VOC_GUILD_75_SCHOLAR;
				done = true;
			} else if (roll > sch && roll <= sag) {
				voc = ChivalrySorceryConstants.VOC_GUILD_76_SAGE;
				done = true;
			} else if (roll > sag && roll <= scr) {
				voc = ChivalrySorceryConstants.VOC_GUILD_77_SCRIBE;
				done = true;
			} else if (roll > scr && roll <= pap) {
				voc = ChivalrySorceryConstants.VOC_GUILD_78_PAPER_INK_MAKER;
				done = true;
			} else {
				voc = ChivalrySorceryConstants.VOC_GUILD_79_LAWYER;
				done = true;
			}
		}
		character.setFatherVocation(voc);
		character.setFatherVocationRank(
				ChivalrySorceryConstants.EMPLOY_RANK_JOURNEYMAN);
	}
	/**
	 * Generates a random noble vocation.
	 * @param character the {@link ChivSorcCharacter}
	 */
	private void assignRandomNobleVocation(
			final ChivSorcCharacter character) {
		int vocation;
		final int c = 100;
		final int b0 = 20, b1 = 40, b2 = 60, b3 = 64, b4 = 69;
		final int b5 = 74, c6 = 79, c7 = 84, c8 = 89;
		final int c9 = 90, d10 = 91, d11 = 92, d12 = 93;
		final int d13 = 94, c14 = 95, c15 = 96, c16 = 97, c17 = 98;
		final int d18 = 99;
		int roll = Diceroller.getInstance().rolldX(c);
		if (roll <= b0) {
			vocation = ChivalrySorceryConstants.VOC_NOB_00_BARON_FRT_CASTLE_1A;
		} else if (roll > b0 && roll <= b1) {
			vocation = ChivalrySorceryConstants.VOC_NOB_01_BARON_FRT_CASTLE_1B;
		} else if (roll > b1 && roll <= b2) {
			vocation = ChivalrySorceryConstants.VOC_NOB_02_BARON_FRT_CASTLE_1F;
		} else if (roll > b2 && roll <= b3) {
			vocation = ChivalrySorceryConstants.VOC_NOB_03_BARON_INT_CASTLE_2;
		} else if (roll > b3 && roll <= b4) {
			vocation = ChivalrySorceryConstants.VOC_NOB_04_BARON_FRT_CASTLE_2;
		} else if (roll > b4 && roll <= b5) {
			vocation = ChivalrySorceryConstants.VOC_NOB_05_BARON_INT_CASTLE_3;
		} else if (roll > b5 && roll <= c6) {
			vocation = ChivalrySorceryConstants.VOC_NOB_06_COUNT_INT_CASTLE_3;
		} else if (roll > c6 && roll <= c7) {
			vocation = ChivalrySorceryConstants.VOC_NOB_07_COUNT_FRT_CASTLE_3;
		} else if (roll > c7 && roll <= c8) {
			vocation = ChivalrySorceryConstants.VOC_NOB_08_COUNT_INT_CASTLE_4;
		} else if (roll > c8 && roll <= c9) {
			vocation = ChivalrySorceryConstants.VOC_NOB_09_COUNT_FRT_CASTLE_4;
		} else if (roll > c9 && roll <= d10) {
			vocation = ChivalrySorceryConstants.VOC_NOB_10_DUKE_INT_CASTLE_4;
		} else if (roll > d10 && roll <= d11) {
			vocation = ChivalrySorceryConstants.VOC_NOB_11_DUKE_FRT_CASTLE_4;
		} else if (roll > d11 && roll <= d12) {
			vocation = ChivalrySorceryConstants.VOC_NOB_12_DUKE_INT_CASTLE_5;
		} else if (roll > d12 && roll <= d13) {
			vocation = ChivalrySorceryConstants.VOC_NOB_13_DUKE_FRT_CASTLE_5;
		} else if (roll > d13 && roll <= c14) {
			vocation = ChivalrySorceryConstants.VOC_NOB_14_COUNT_INT_CASTLE_1A;
		} else if (roll > c14 && roll <= c15) {
			vocation = ChivalrySorceryConstants.VOC_NOB_15_COUNT_INT_CASTLE_1C;
		} else if (roll > c15 && roll <= c16) {
			vocation = ChivalrySorceryConstants.VOC_NOB_16_COUNT_INT_CASTLE_1E;
		} else if (roll > c16 && roll <= c17) {
			vocation = ChivalrySorceryConstants.VOC_NOB_17_COUNT_INT_CASTLE_3;
		} else if (roll > c17 && roll <= d18) {
			vocation = ChivalrySorceryConstants.VOC_NOB_18_DUKE_INT_CASTLE_5;
		} else {
			vocation = ChivalrySorceryConstants.VOC_NOB_19_DUKE_INT_CASTLE_6;
		}
		character.setFatherVocation(vocation);
		character.setFatherVocationRank(
				ChivalrySorceryConstants.EMPLOY_RANK_JOURNEYMAN);
	}
	/**
	 * Generates a random royal vocation.
	 * @param character the {@link ChivSorcCharacter}
	 */
	private void assignRandomRoyalVocation(
			final ChivSorcCharacter character) {
		int vocation;
		final int c = 100;
		final int b0 = 20, b1 = 40, b2 = 60, b3 = 64, b4 = 69;
		final int b5 = 74, c6 = 79, c7 = 84, c8 = 89;
		final int c9 = 90, d10 = 91, d11 = 92, d12 = 93;
		final int d13 = 94, c14 = 95, c15 = 96, c16 = 97, c17 = 98;
		final int d18 = 99;
		int roll = Diceroller.getInstance().rolldX(c);
		if (roll <= b0) {
			vocation = ChivalrySorceryConstants.VOC_ROY_00_KNIGHT_FRT_CASTLE_1A;
		} else if (roll > b0 && roll <= b1) {
			vocation = ChivalrySorceryConstants.VOC_ROY_01_BANNERETTE_FRT_CASTLE_1B;
		} else if (roll > b1 && roll <= b2) {
			vocation = ChivalrySorceryConstants.VOC_ROY_02_BARON_FRT_CASTLE_1F;
		} else if (roll > b2 && roll <= b3) {
			vocation = ChivalrySorceryConstants.VOC_ROY_03_BARON_INT_CASTLE_2;
		} else if (roll > b3 && roll <= b4) {
			vocation = ChivalrySorceryConstants.VOC_ROY_04_BARON_FRT_CASTLE_2;
		} else if (roll > b4 && roll <= b5) {
			vocation = ChivalrySorceryConstants.VOC_ROY_05_BARON_INT_CASTLE_3;
		} else if (roll > b5 && roll <= c6) {
			vocation = ChivalrySorceryConstants.VOC_ROY_06_COUNT_INT_CASTLE_3;
		} else if (roll > c6 && roll <= c7) {
			vocation = ChivalrySorceryConstants.VOC_ROY_07_COUNT_FRT_CASTLE_3;
		} else if (roll > c7 && roll <= c8) {
			vocation = ChivalrySorceryConstants.VOC_ROY_08_COUNT_INT_CASTLE_4;
		} else if (roll > c8 && roll <= c9) {
			vocation = ChivalrySorceryConstants.VOC_ROY_09_COUNT_FRT_CASTLE_4;
		} else if (roll > c9 && roll <= d10) {
			vocation = ChivalrySorceryConstants.VOC_ROY_10_DUKE_INT_CASTLE_4;
		} else if (roll > d10 && roll <= d11) {
			vocation = ChivalrySorceryConstants.VOC_ROY_11_DUKE_FRT_CASTLE_4;
		} else if (roll > d11 && roll <= d12) {
			vocation = ChivalrySorceryConstants.VOC_ROY_12_DUKE_INT_CASTLE_5;
		} else if (roll > d12 && roll <= d13) {
			vocation = ChivalrySorceryConstants.VOC_ROY_13_DUKE_FRT_CASTLE_5;
		} else if (roll > d13 && roll <= c14) {
			vocation = ChivalrySorceryConstants.VOC_ROY_14_COUNT_INT_CASTLE_1A;
		} else if (roll > c14 && roll <= c15) {
			vocation = ChivalrySorceryConstants.VOC_ROY_15_COUNT_INT_CASTLE_1C;
		} else if (roll > c15 && roll <= c16) {
			vocation = ChivalrySorceryConstants.VOC_ROY_16_COUNT_INT_CASTLE_1E;
		} else if (roll > c16 && roll <= c17) {
			vocation = ChivalrySorceryConstants.VOC_ROY_17_COUNT_INT_CASTLE_3;
		} else if (roll > c17 && roll <= d18) {
			vocation = ChivalrySorceryConstants.VOC_ROY_18_DUKE_INT_CASTLE_5;
		} else {
			vocation = ChivalrySorceryConstants.VOC_ROY_19_KING_INT_CASTLE_6;
		}
		character.setFatherVocation(vocation);
		character.setFatherVocationRank(
				ChivalrySorceryConstants.EMPLOY_RANK_JOURNEYMAN);
	}
	/**
	 * Generates a random serf vocation.
	 * @param character the {@link ChivSorcCharacter}
	 */
	private void assignRandomSerfVocation(
			final ChivSorcCharacter character) {
		int vocation;
		final int c = 100;
		final int farmer = 65, horse = 75, cow = 80, swine = 85, shep = 90, serv = 95, cook = 96, black = 97, arm = 98, serv2 = 99;
		int roll = Diceroller.getInstance().rolldX(c);
		if (character.getBirthAspect()
				== ChivalrySorceryConstants.ASPECT_00_AUSPICIOUS) {
			roll -= 5;
		}
		if (roll <= farmer) {
			vocation = ChivalrySorceryConstants.VOC_SERF_00_FARMER;
		} else if (roll > farmer && roll <= horse) {
			vocation = ChivalrySorceryConstants.VOC_SERF_01_HORSE_HANDLER;
		} else if (roll > horse && roll <= cow) {
			vocation = ChivalrySorceryConstants.VOC_SERF_02_COWHERD;
		} else if (roll > cow && roll <= swine) {
			vocation = ChivalrySorceryConstants.VOC_SERF_03_SWINEHERD;
		} else if (roll > swine && roll <= shep) {
			vocation = ChivalrySorceryConstants.VOC_SERF_04_SHEPHERD;
		} else if (roll > shep && roll <= serv) {
			vocation = ChivalrySorceryConstants.VOC_SERF_05_CASTLE_SERVANT;
		} else if (roll > serv && roll <= cook) {
			vocation = ChivalrySorceryConstants.VOC_SERF_06_COOKS_ASSISTANT;
		} else if (roll > cook && roll <= black) {
			vocation = ChivalrySorceryConstants.VOC_SERF_07_BLACKSMITHS_ASSISTANT;
		} else if (roll > black && roll <= arm) {
			vocation = ChivalrySorceryConstants.VOC_SERF_08_ARMORERS_ASSISTANT;
		} else if (roll > arm && roll <= serv2) {
			vocation = ChivalrySorceryConstants.VOC_SERF_09_HIRED_SERVANT;
		} else {
			vocation = ChivalrySorceryConstants.VOC_SERF_10_HIRED_LABORER;
		}
		character.setFatherVocation(vocation);
		character.setFatherVocationRank(
				ChivalrySorceryConstants.EMPLOY_RANK_JOURNEYMAN);
	}
	/**
	 * Generates a random sibling rank for a character.
	 * @param character the {@link ChivSorcCharacter}
	 */
	private void assignRandomSiblings(final ChivSorcCharacter character) {
		int sibling;
		final int c = 100;
		final int bastU = 10, bastA = 20, sixth = 35, fifth = 50, fourth = 65, third = 80, second = 95;
		int roll = Diceroller.getInstance().rolldX(c);
		if (character.getBirthAspect()
				== ChivalrySorceryConstants.ASPECT_00_AUSPICIOUS) {
			roll += 15;
		} else if (character.getBirthAspect()
				== ChivalrySorceryConstants.ASPECT_01_NEUTRAL) {
			roll += 5;
		} else {
			roll -= 10;
		}
		if (roll <= bastU) {
			sibling = ChivalrySorceryConstants.SIBLINGS_BASTARD_UNACKNOWLEDGED;
		} else if (roll > bastU && roll <= bastA) {
			sibling = ChivalrySorceryConstants.SIBLINGS_BASTARD_ACKNOWLEDGED;
		} else if (roll > bastA && roll <= sixth) {
			sibling = ChivalrySorceryConstants.SIBLINGS_6TH_CHILD;
		} else if (roll > sixth && roll <= fifth) {
			sibling = ChivalrySorceryConstants.SIBLINGS_5TH_CHILD;
		} else if (roll > fifth && roll <= fourth) {
			sibling = ChivalrySorceryConstants.SIBLINGS_4TH_CHILD;
		} else if (roll > fourth && roll <= third) {
			sibling = ChivalrySorceryConstants.SIBLINGS_3RD_CHILD;
		} else if (roll > third && roll <= second) {
			sibling = ChivalrySorceryConstants.SIBLINGS_2ND_CHILD;
		} else {
			sibling = ChivalrySorceryConstants.SIBLINGS_1ST_CHILD;
		}
		character.setSiblingRank(sibling);
	}
	/**
	 * Generates a random social class for a character's parents.
	 * @param character the {@link ChivSorcCharacter}
	 */
	private void assignRandomSocialClass(
			final ChivSorcCharacter character) {
		int social;
		final int c = 100;
		final int serf = 10, yeoman = 40, townsman = 60, guildsman = 80, chivalric = 95, noble = 99;
		int roll = Diceroller.getInstance().rolldX(c);
		if (character.getBirthAspect()
				== ChivalrySorceryConstants.ASPECT_00_AUSPICIOUS) {
			roll += 10;
		} else if (character.getBirthAspect()
				== ChivalrySorceryConstants.ASPECT_02_INAUSPICIOUS) {
			roll -= 10;
		}
		boolean allowed = true;
		do {
			if (roll <= serf) {
				social = ChivalrySorceryConstants.BIRTH_CLASS_00_SERF;
			} else if (roll > serf && roll <= yeoman) {
				social = ChivalrySorceryConstants.BIRTH_CLASS_01_YEOMAN;
			} else if (roll > yeoman && roll <= townsman) {
				social = ChivalrySorceryConstants.BIRTH_CLASS_02_TOWNSMAN;
			} else if (roll > townsman && roll <= guildsman) {
				social = ChivalrySorceryConstants.BIRTH_CLASS_03_GUILDSMAN;
			} else if (roll > guildsman && roll <= chivalric) {
				social = ChivalrySorceryConstants.BIRTH_CLASS_04_CHIVALRIC;
			} else if (roll > chivalric && roll <= noble) {
				social = ChivalrySorceryConstants.BIRTH_CLASS_05_NOBLE;
			} else {
				social = ChivalrySorceryConstants.BIRTH_CLASS_06_ROYAL;
			}
			if (character.getSiblingRank()
						== ChivalrySorceryConstants.SIBLINGS_BASTARD_UNACKNOWLEDGED
					&& social
						== ChivalrySorceryConstants.BIRTH_CLASS_06_ROYAL) {
				// no unacknowledged royal bastards
				allowed = false;
			}
		} while (!allowed);
		character.setFatherSocialClass(social);
	}
	/**
	 * Generates a random townsman vocation.
	 * @param character the {@link ChivSorcCharacter}
	 */
	private void assignRandomTownsmanVocation(
			final ChivSorcCharacter character) {
		int vocation;
		final int c = 100;
		final int barrow = 5, tinker = 10, peddlar = 15, beer = 20, miner = 25;
		final int owner = 30, brothel = 35, ostler = 40, cobbler = 45;
		final int grocer = 50, lender = 55, cart = 60, harness = 65;
		final int barber = 70, butcher = 75, smith = 80, baker = 85, wine = 90;
		int roll = Diceroller.getInstance().rolldX(c);
		if (roll <= barrow) {
			vocation = ChivalrySorceryConstants.VOC_TOWN_00_BARROW_WIGHT;
		} else if (roll > barrow && roll <= tinker) {
			vocation = ChivalrySorceryConstants.VOC_TOWN_01_TINKER;
		} else if (roll > tinker && roll <= peddlar) {
			vocation = ChivalrySorceryConstants.VOC_TOWN_02_PEDDLAR;
		} else if (roll > peddlar && roll <= beer) {
			vocation = ChivalrySorceryConstants.VOC_TOWN_03_BEER_PEDDLAR;
		} else if (roll > beer && roll <= miner) {
			vocation = ChivalrySorceryConstants.VOC_TOWN_04_MINER;
		} else if (roll > miner && roll <= owner) {
			vocation = ChivalrySorceryConstants.VOC_TOWN_05_MINE_OWNER;
		} else if (roll > owner && roll <= brothel) {
			vocation = ChivalrySorceryConstants.VOC_TOWN_06_BROTHELKEEPER;
		} else if (roll > brothel && roll <= ostler) {
			vocation = ChivalrySorceryConstants.VOC_TOWN_07_OSTLER;
		} else if (roll > ostler && roll <= cobbler) {
			vocation = ChivalrySorceryConstants.VOC_TOWN_08_COBBLER;
		} else if (roll > cobbler && roll <= grocer) {
			vocation = ChivalrySorceryConstants.VOC_TOWN_09_GREENGROCER;
		} else if (roll > grocer && roll <= lender) {
			vocation = ChivalrySorceryConstants.VOC_TOWN_10_MONEYLENDER;
		} else if (roll > lender && roll <= cart) {
			vocation = ChivalrySorceryConstants.VOC_TOWN_11_CARTWRIGHT;
		} else if (roll > cart && roll <= harness) {
			vocation = ChivalrySorceryConstants.VOC_TOWN_12_HARNESSMAKER;
		} else if (roll > harness && roll <= barber) {
			vocation = ChivalrySorceryConstants.VOC_TOWN_13_BARBER;
		} else if (roll > barber && roll <= butcher) {
			vocation = ChivalrySorceryConstants.VOC_TOWN_14_BUTCHER;
		} else if (roll > butcher && roll <= smith) {
			vocation = ChivalrySorceryConstants.VOC_TOWN_15_BLACKSMITH;
		} else if (roll > smith && roll <= baker) {
			vocation = ChivalrySorceryConstants.VOC_TOWN_16_BAKER;
		} else if (roll > baker && roll <= wine) {
			vocation = ChivalrySorceryConstants.VOC_TOWN_17_WINE_MERCHANT;
		} else {
			vocation = ChivalrySorceryConstants.VOC_TOWN_18_INNKEEPER;
		}
		character.setFatherVocation(vocation);
		character.setFatherVocationRank(
				ChivalrySorceryConstants.EMPLOY_RANK_JOURNEYMAN);
	}
	/**
	 * Generates a random yeoman vocation.
	 * @param character the {@link ChivSorcCharacter}
	 */
	private void assignRandomYeomanVocation(
			final ChivSorcCharacter character) {
		int vocation;
		final int c = 100;
		final int cook = 2, blacksmith = 4, armorer = 6, falconer = 7;
		final int trainer = 9, forester = 20, innkeeper = 25, carpenter = 30;
		final int mason = 35, forester2 = 40, fisherman = 43, manatarms = 48;
		final int archer = 53, miller = 55, farmer = 80, stockman = 90;
		final int sergeant = 95;
		int roll = Diceroller.getInstance().rolldX(c);
		if (character.getBirthAspect()
				== ChivalrySorceryConstants.ASPECT_00_AUSPICIOUS) {
			roll += 5;
		}
		if (roll <= cook) {
			vocation = ChivalrySorceryConstants.VOC_YEO_03_LIVERIED_COOK;
		} else if (roll > cook && roll <= blacksmith) {
			vocation = ChivalrySorceryConstants.VOC_YEO_04_LIVERIED_BLACKSMITH;
		} else if (roll > blacksmith && roll <= armorer) {
			vocation = ChivalrySorceryConstants.VOC_YEO_05_LIVERIED_ARMOURER;
		} else if (roll > armorer && roll <= falconer) {
			vocation = ChivalrySorceryConstants.VOC_YEO_06_LIVERIED_FALCONER;
		} else if (roll > falconer && roll <= trainer) {
			vocation = ChivalrySorceryConstants.VOC_YEO_07_LIVERIED_ANIMAL_TRAINER;
		} else if (roll > trainer && roll <= forester) {
			vocation = ChivalrySorceryConstants.VOC_YEO_08_LIVERIED_FORESTER;
		} else if (roll > forester && roll <= innkeeper) {
			vocation = ChivalrySorceryConstants.VOC_YEO_09_INNKEEPER;
		} else if (roll > innkeeper && roll <= carpenter) {
			vocation = ChivalrySorceryConstants.VOC_YEO_10_CARPENTER;
		} else if (roll > carpenter && roll <= mason) {
			vocation = ChivalrySorceryConstants.VOC_YEO_11_MASON;
		} else if (roll > mason && roll <= forester2) {
			vocation = ChivalrySorceryConstants.VOC_YEO_12_FORESTER;
		} else if (roll > forester2 && roll <= fisherman) {
			vocation = ChivalrySorceryConstants.VOC_YEO_13_FISHERMAN;
		} else if (roll > fisherman && roll <= manatarms) {
			vocation = ChivalrySorceryConstants.VOC_YEO_00_LIVERIED_MAN_AT_ARMS;
		} else if (roll > manatarms && roll <= archer) {
			vocation =
					ChivalrySorceryConstants.VOC_YEO_01_LIVERIED_ARCHER;
		} else if (roll > archer && roll <= miller) {
			vocation = ChivalrySorceryConstants.VOC_YEO_14_MILLER;
		} else if (roll > miller && roll <= farmer) {
			vocation = ChivalrySorceryConstants.VOC_YEO_15_FARMER;
		} else if (roll > farmer && roll <= stockman) {
			vocation = ChivalrySorceryConstants.VOC_YEO_16_STOCKMAN;
		} else if (roll > stockman && roll <= sergeant) {
			vocation = ChivalrySorceryConstants.VOC_YEO_02_LIVERIED_SERGEANT;
		} else {
			vocation = ChivalrySorceryConstants.VOC_YEO_17_PETIT_SERGEANT;
		}
		character.setFatherVocation(vocation);
		character.setFatherVocationRank(
				ChivalrySorceryConstants.EMPLOY_RANK_JOURNEYMAN);
	}
	/**
	 * Determines if a character is his father's heir.
	 * @param character the {@link ChivSorcCharacter}
	 */
	private void determineIfHeir(final ChivSorcCharacter character) {
		boolean is = false;
		if (character.getSiblingRank()
				== ChivalrySorceryConstants.SIBLINGS_1ST_CHILD) {
			// eldest - find out how many siblings, and if another is heir
			character.setNumSiblings(Diceroller.getInstance().rolldX(6));
			if (character.getGender() == ChivalrySorceryConstants.GENDER_MALE) {
				// oldest son - you ARE the heir
				is = true;
			} else {
				// only heir if parents had all daughters
				boolean hasBrother = false;
				for (int i = 0, ln = character.getNumSiblings(); i < ln; i++) {
					if (Diceroller.getInstance().rolldX(6) % 2 == 0) {
						// a son is born!
						hasBrother = true;
						break;
					}
				}
				if (!hasBrother) {
					// oldest daughter and no brothers - you ARE the heir
					is = true;
				}
			}
		} else if (character.getSiblingRank()
					== ChivalrySorceryConstants.SIBLINGS_BASTARD_ACKNOWLEDGED
				|| character.getSiblingRank()
					== ChivalrySorceryConstants.SIBLINGS_BASTARD_UNACKNOWLEDGED) {
			// bastard - not the heir, and find num siblings
			character.setNumSiblings(Diceroller.getInstance().rolldX(6));
		} else {
			// youngest child. get number of siblings
			character.setNumSiblings(character.getSiblingRank());
			if (character.getGender() == ChivalrySorceryConstants.GENDER_MALE) {
				// a son - could you be the heir?
				boolean hasBrother = false;
				for (int i = 0, ln = character.getNumSiblings(); i < ln; i++) {
					if (Diceroller.getInstance().rolldX(6) % 2 == 0) {
						// a son is born!
						hasBrother = true;
						break;
					}
				}
				if (!hasBrother) {
					// oldest son - you ARE the heir
					is = true;
				}
			}
		}
	}
	/**
	 * Generates a random set of birth omens for a character. One's fate is
	 * written in the stars.
	 * @param character the {@link ChivSorcCharacter} being affected
	 */
	public void generateBirthOmens(final ChivSorcCharacter character) {
		// set birth aspect
		final int good = 25, bad = 76, c = 100;
		int roll = Diceroller.getInstance().rolldX(c);
		if (roll <= good) {
			character.setBirthAspect(
					ChivalrySorceryConstants.ASPECT_00_AUSPICIOUS);
		} else if (roll > good && roll < bad) {
			character.setBirthAspect(
					ChivalrySorceryConstants.ASPECT_01_NEUTRAL);
		} else {
			character.setBirthAspect(
					ChivalrySorceryConstants.ASPECT_02_INAUSPICIOUS);
		}
		// set zodiac
		roll = Diceroller.getInstance().rolldX(c);
		final int ari = 10, tau = 18, gem = 25, can = 32, leo = 40, vir = 48, lib = 56, sco = 64, sag = 72, cap = 80, aqu = 88;
		if (roll <= ari) {
			character.setZodiac(ChivalrySorceryConstants.ZODIAC_00_ARIES);
		} else if (roll > ari && roll <= tau) {
			character.setZodiac(ChivalrySorceryConstants.ZODIAC_01_TAURUS);
		} else if (roll > tau && roll <= gem) {
			character.setZodiac(ChivalrySorceryConstants.ZODIAC_02_GEMINI);
		} else if (roll > gem && roll <= can) {
			character.setZodiac(ChivalrySorceryConstants.ZODIAC_03_CANCER);
		} else if (roll > can && roll <= leo) {
			character.setZodiac(ChivalrySorceryConstants.ZODIAC_04_LEO);
		} else if (roll > leo && roll <= vir) {
			character.setZodiac(ChivalrySorceryConstants.ZODIAC_05_VIRGO);
		} else if (roll > vir && roll <= lib) {
			character.setZodiac(ChivalrySorceryConstants.ZODIAC_06_LIBRA);
		} else if (roll > lib && roll <= sco) {
			character.setZodiac(ChivalrySorceryConstants.ZODIAC_07_SCORPIO);
		} else if (roll > sco && roll <= sag) {
			character.setZodiac(ChivalrySorceryConstants.ZODIAC_08_SAGITTARIUS);
		} else if (roll > sag && roll <= cap) {
			character.setZodiac(ChivalrySorceryConstants.ZODIAC_09_CAPRICORN);
		} else if (roll > cap && roll <= aqu) {
			character.setZodiac(ChivalrySorceryConstants.ZODIAC_10_AQUARIUS);
		} else {
			character.setZodiac(ChivalrySorceryConstants.ZODIAC_11_PISCES);
		}
	}
	/**
	 * Generates random body sizes for a human female based on a random roll.
	 * @param character the {@link ChivSorcCharacter} being affected
	 * @param roll random percentage roll.
	 */
	private void generateHumanFemaleBody(
			final ChivSorcCharacter character, final int roll) {
		if (roll == 1) {
			character.setBaseheight(53);
			character.setBaseweight(78);
		} else if (roll == 2) {
			character.setBaseheight(54);
			character.setBaseweight(82);
		} else if (roll == 3) {
			character.setBaseheight(55);
			character.setBaseweight(86);
		} else if (roll == 4) {
			character.setBaseheight(56);
			character.setBaseweight(90);
		} else if (roll == 5) {
			character.setBaseheight(57);
			character.setBaseweight(94);
		} else if (roll >= 6 && roll <= 7) {
			character.setBaseheight(58);
			character.setBaseweight(98);
		} else if (roll >= 8 && roll <= 10) {
			character.setBaseheight(59);
			character.setBaseweight(102);
		} else if (roll >= 11 && roll <= 14) {
			character.setBaseheight(60);
			character.setBaseweight(106);
		} else if (roll >= 15 && roll <= 19) {
			character.setBaseheight(61);
			character.setBaseweight(110);
		} else if (roll >= 20 && roll <= 24) {
			character.setBaseheight(62);
			character.setBaseweight(113);
		} else if (roll >= 25 && roll <= 29) {
			character.setBaseheight(63);
			character.setBaseweight(116);
		} else if (roll >= 30 && roll <= 34) {
			character.setBaseheight(64);
			character.setBaseweight(120);
		} else if (roll >= 35 && roll <= 39) {
			character.setBaseheight(65);
			character.setBaseweight(124);
		} else if (roll >= 40 && roll <= 44) {
			character.setBaseheight(66);
			character.setBaseweight(128);
		} else if (roll >= 45 && roll <= 49) {
			character.setBaseheight(67);
			character.setBaseweight(132);
		} else if (roll >= 50 && roll <= 59) {
			character.setBaseheight(68);
			character.setBaseweight(136);
		} else if (roll >= 60 && roll <= 69) {
			character.setBaseheight(69);
			character.setBaseweight(140);
		} else if (roll >= 70 && roll <= 78) {
			character.setBaseheight(70);
			character.setBaseweight(144);
		} else if (roll >= 79 && roll <= 84) {
			character.setBaseheight(71);
			character.setBaseweight(148);
		} else if (roll >= 85 && roll <= 88) {
			character.setBaseheight(72);
			character.setBaseweight(153);
		} else if (roll >= 89 && roll <= 91) {
			character.setBaseheight(73);
			character.setBaseweight(158);
		} else if (roll >= 92 && roll <= 94) {
			character.setBaseheight(74);
			character.setBaseweight(164);
		} else if (roll >= 95 && roll <= 96) {
			character.setBaseheight(75);
			character.setBaseweight(170);
		} else if (roll == 97) {
			character.setBaseheight(76);
			character.setBaseweight(180);
		} else if (roll == 98) {
			character.setBaseheight(77);
			character.setBaseweight(190);
		} else if (roll == 99) {
			character.setBaseheight(78);
			character.setBaseweight(200);
		} else {
			character.setBaseheight(79);
			character.setBaseweight(210);
		}
		setHumanBodyLevelForWeight(character);
	}
	/**
	 * Generates random body sizes for a human male based on a random roll.
	 * @param character the {@link ChivSorcCharacter} being affected
	 * @param roll random percentage roll.
	 */
	private void generateHumanMaleBody(
			final ChivSorcCharacter character, final int roll) {
		if (roll == 1) {
			character.setBaseheight(54);
			character.setBaseweight(82);
		} else if (roll == 2) {
			character.setBaseheight(55);
			character.setBaseweight(86);
		} else if (roll == 3) {
			character.setBaseheight(56);
			character.setBaseweight(90);
		} else if (roll == 4) {
			character.setBaseheight(57);
			character.setBaseweight(94);
		} else if (roll == 5) {
			character.setBaseheight(58);
			character.setBaseweight(98);
		} else if (roll >= 6 && roll <= 7) {
			character.setBaseheight(59);
			character.setBaseweight(102);
		} else if (roll >= 8 && roll <= 10) {
			character.setBaseheight(60);
			character.setBaseweight(106);
		} else if (roll >= 11 && roll <= 14) {
			character.setBaseheight(61);
			character.setBaseweight(110);
		} else if (roll >= 15 && roll <= 19) {
			character.setBaseheight(62);
			character.setBaseweight(115);
		} else if (roll >= 20 && roll <= 24) {
			character.setBaseheight(63);
			character.setBaseweight(120);
		} else if (roll >= 25 && roll <= 29) {
			character.setBaseheight(64);
			character.setBaseweight(125);
		} else if (roll >= 30 && roll <= 34) {
			character.setBaseheight(65);
			character.setBaseweight(130);
		} else if (roll >= 35 && roll <= 39) {
			character.setBaseheight(66);
			character.setBaseweight(135);
		} else if (roll >= 40 && roll <= 44) {
			character.setBaseheight(67);
			character.setBaseweight(140);
		} else if (roll >= 45 && roll <= 49) {
			character.setBaseheight(68);
			character.setBaseweight(145);
		} else if (roll >= 50 && roll <= 59) {
			character.setBaseheight(69);
			character.setBaseweight(150);
		} else if (roll >= 60 && roll <= 69) {
			character.setBaseheight(70);
			character.setBaseweight(156);
		} else if (roll >= 70 && roll <= 78) {
			character.setBaseheight(71);
			character.setBaseweight(163);
		} else if (roll >= 79 && roll <= 84) {
			character.setBaseheight(72);
			character.setBaseweight(170);
		} else if (roll >= 85 && roll <= 88) {
			character.setBaseheight(73);
			character.setBaseweight(177);
		} else if (roll >= 89 && roll <= 91) {
			character.setBaseheight(74);
			character.setBaseweight(185);
		} else if (roll >= 92 && roll <= 94) {
			character.setBaseheight(75);
			character.setBaseweight(194);
		} else if (roll >= 95 && roll <= 96) {
			character.setBaseheight(76);
			character.setBaseweight(204);
		} else if (roll == 97) {
			character.setBaseheight(77);
			character.setBaseweight(215);
		} else if (roll == 98) {
			character.setBaseheight(78);
			character.setBaseweight(230);
		} else if (roll == 99) {
			character.setBaseheight(79);
			character.setBaseweight(245);
		} else {
			character.setBaseheight(80);
			character.setBaseweight(260);
		}
		setHumanBodyLevelForWeight(character);
	}
	/**
	 * Generates random size for a character.
	 * @param character the {@link ChivSorcCharacter} being affected
	 * @throws Exception if an error occurs
	 */
	public void generateSize(final ChivSorcCharacter character)
			throws Exception {
		final int c = 100, t = 20;
		// get body frame
		final int vl = 2, l = 7, avg = 15, lg = 19;
		boolean done = false;
		while (!done) {
			int roll = Diceroller.getInstance().rolldX(t);
			switch (character.getRace()) {
			case ChivalrySorceryConstants.PLAYER_RACE_01_WOOD_ELF:
			case ChivalrySorceryConstants.PLAYER_RACE_02_HIGH_ELF:
				roll--;
				break;
			case ChivalrySorceryConstants.PLAYER_RACE_03_DWARF:
				roll += 2;
				break;
			case ChivalrySorceryConstants.PLAYER_RACE_04_HAEFLING:
				roll++;
				break;
			}
			if (character.getGender() == ChivalrySorceryConstants.GENDER_FEMALE) {
				roll -= 2;
			}
			if (roll <= vl) {
				character
						.setBaseframe(ChivalrySorceryConstants.BODY_FRAME_00_VERY_LIGHT);
				done = true;
			} else if (roll > vl && roll <= l) {
				character
						.setBaseframe(ChivalrySorceryConstants.BODY_FRAME_01_LIGHT);
				done = true;
			} else if (roll > l && roll <= avg) {
				character
						.setBaseframe(ChivalrySorceryConstants.BODY_FRAME_02_AVERAGE);
				done = true;
			} else if (roll > avg && roll <= lg) {
				if (character.getGender() == ChivalrySorceryConstants.GENDER_FEMALE
						&& (character.getRace() == ChivalrySorceryConstants.PLAYER_RACE_01_WOOD_ELF
						|| character.getRace() == ChivalrySorceryConstants.PLAYER_RACE_02_HIGH_ELF)) {
					done = false;
				} else {
					character
							.setBaseframe(ChivalrySorceryConstants.BODY_FRAME_03_LARGE);
					done = true;
				}
			} else {
				character
						.setBaseframe(ChivalrySorceryConstants.BODY_FRAME_04_MASSIVE);
				done = true;
			}
		}
		int roll = Diceroller.getInstance().rolldX(c);
		// get body size
		switch (character.getRace()) {
		case ChivalrySorceryConstants.PLAYER_RACE_00_HUMAN:
		case ChivalrySorceryConstants.PLAYER_RACE_01_WOOD_ELF:
		case ChivalrySorceryConstants.PLAYER_RACE_02_HIGH_ELF:
			if (character.getGender() == ChivalrySorceryConstants.GENDER_FEMALE) {
				generateHumanFemaleBody(character, roll);
			} else {
				generateHumanMaleBody(character, roll);
			}
			break;
		case ChivalrySorceryConstants.PLAYER_RACE_03_DWARF:
			if (roll <= 15) {
				character.setBaseheight(42);
				character.setBaseweight(82);
			} else if (roll <= 30) {
				character.setBaseheight(43);
				character.setBaseweight(85);
			} else if (roll <= 40) {
				character.setBaseheight(44);
				character.setBaseweight(88);
			} else if (roll <= 50) {
				character.setBaseheight(45);
				character.setBaseweight(91);
			} else if (roll <= 60) {
				character.setBaseheight(46);
				character.setBaseweight(94);
			} else if (roll <= 70) {
				character.setBaseheight(47);
				character.setBaseweight(97);
			} else if (roll <= 80) {
				character.setBaseheight(48);
				character.setBaseweight(100);
			} else if (roll <= 85) {
				character.setBaseheight(49);
				character.setBaseweight(105);
			} else if (roll <= 90) {
				character.setBaseheight(50);
				character.setBaseweight(110);
			} else if (roll <= 94) {
				character.setBaseheight(51);
				character.setBaseweight(115);
			} else if (roll <= 97) {
				character.setBaseheight(52);
				character.setBaseweight(120);
			} else if (roll <= 99) {
				character.setBaseheight(53);
				character.setBaseweight(125);
			} else {
				character.setBaseheight(54);
				character.setBaseweight(130);
			}
			getDwarfBodyLevelForWeight(character);
			break;
		case ChivalrySorceryConstants.PLAYER_RACE_04_HAEFLING:
			if (roll <= 10) {
				character.setBaseheight(42);
				character.setBaseweight(59);
			} else if (roll <= 20) {
				character.setBaseheight(43);
				character.setBaseweight(62);
			} else if (roll <= 30) {
				character.setBaseheight(44);
				character.setBaseweight(65);
			} else if (roll <= 40) {
				character.setBaseheight(45);
				character.setBaseweight(68);
			} else if (roll <= 50) {
				character.setBaseheight(46);
				character.setBaseweight(72);
			} else if (roll <= 60) {
				character.setBaseheight(47);
				character.setBaseweight(76);
			} else if (roll <= 70) {
				character.setBaseheight(48);
				character.setBaseweight(80);
			} else if (roll <= 80) {
				character.setBaseheight(49);
				character.setBaseweight(84);
			} else if (roll <= 85) {
				character.setBaseheight(50);
				character.setBaseweight(88);
			} else if (roll <= 90) {
				character.setBaseheight(51);
				character.setBaseweight(92);
			} else if (roll <= 95) {
				character.setBaseheight(52);
				character.setBaseweight(96);
			} else if (roll <= 98) {
				character.setBaseheight(53);
				character.setBaseweight(100);
			} else {
				character.setBaseheight(54);
				character.setBaseweight(105);
			}
			getHaeflingBodyLevelForWeight(character);
			break;
		default:
			PooledStringBuilder sb =
					StringBuilderPool.getInstance().getStringBuilder();
			sb.append("Invalid player race: ");
			sb.append(character.getRace());
			sb.append(".");
			Exception ex = new Exception(sb.toString());
			sb.returnToPool();
			sb = null;
			throw ex;
		}
	}
	/**
	 * Generates a random social history for a character, based on his or her
	 * race.
	 * @param character the {@link ChivSorcCharacter} being affected
	 * @throws Exception if an error occurs
	 */
	public void generateSocialHistory(final ChivSorcCharacter character)
			throws Exception {
		final int c = 100;
		switch (character.getRace()) {
		case ChivalrySorceryConstants.PLAYER_RACE_00_HUMAN:
			assignRandomSiblings(character);
			assignRandomSocialClass(character);
			determineIfHeir(character);
			assignRandomFamilyStatus(character);
			switch (character.getFatherSocialClass()) {
			case ChivalrySorceryConstants.BIRTH_CLASS_00_SERF:
				assignRandomSerfVocation(character);
				break;
			case ChivalrySorceryConstants.BIRTH_CLASS_01_YEOMAN:
				assignRandomYeomanVocation(character);
				break;
			case ChivalrySorceryConstants.BIRTH_CLASS_02_TOWNSMAN:
				assignRandomTownsmanVocation(character);
				break;
			case ChivalrySorceryConstants.BIRTH_CLASS_03_GUILDSMAN:
				assignRandomGuildsmanVocation(character);
				break;
			case ChivalrySorceryConstants.BIRTH_CLASS_04_CHIVALRIC:
				assignRandomChivalricVocation(character);
				break;
			case ChivalrySorceryConstants.BIRTH_CLASS_05_NOBLE:
				assignRandomNobleVocation(character);
				break;
			case ChivalrySorceryConstants.BIRTH_CLASS_06_ROYAL:
				assignRandomRoyalVocation(character);
				break;
			default:
				PooledStringBuilder sb =
						StringBuilderPool.getInstance().getStringBuilder();
				sb.append("Invalid player birth class: ");
				sb.append(character.getRace());
				sb.append(".");
				Exception ex = new Exception(sb.toString());
				sb.returnToPool();
				sb = null;
				throw ex;
			}
			break;
		case ChivalrySorceryConstants.PLAYER_RACE_01_WOOD_ELF:
			character.setFatherVocation(
					ChivalrySorceryConstants.VOC_CHIV_00_KNIGHT_INT_SFMH_1);
			break;
		case ChivalrySorceryConstants.PLAYER_RACE_02_HIGH_ELF:
			assignRandomNobleVocation(character);
			break;
		case ChivalrySorceryConstants.PLAYER_RACE_03_DWARF:
			final int guild = 90,
			e0 = 95,
			e1 = 96,
			e2 = 97,
			e3 = 98,
			e4 = 99;
			int roll = Diceroller.getInstance().rolldX(c);
			if (roll <= guild) {
				assignRandomGuildsmanVocation(character);
			} else if (roll > guild && roll <= e0) {
				character.setFatherVocation(
						ChivalrySorceryConstants.VOC_DWF_00_EALDOR);
			} else if (roll > e0 && roll <= e1) {
				character.setFatherVocation(
						ChivalrySorceryConstants.VOC_DWF_01_EALDOR);
			} else if (roll > e1 && roll <= e2) {
				character.setFatherVocation(
						ChivalrySorceryConstants.VOC_DWF_02_EALDOR);
			} else if (roll > e2 && roll <= e3) {
				character.setFatherVocation(
						ChivalrySorceryConstants.VOC_DWF_03_EALDOR);
			} else if (roll > e3 && roll <= e4) {
				character.setFatherVocation(
						ChivalrySorceryConstants.VOC_DWF_04_EALDOR);
			} else {
				character.setFatherVocation(
						ChivalrySorceryConstants.VOC_DWF_05_KING);
			}
			break;
		case ChivalrySorceryConstants.PLAYER_RACE_04_HAEFLING:
			final int yeo = 75,
			town = 85;
			roll = Diceroller.getInstance().rolldX(c);
			if (roll <= yeo) {
				assignRandomSerfVocation(character);
			} else if (roll > yeo && roll <= town) {
				assignRandomTownsmanVocation(character);
			} else {
				assignRandomGuildsmanVocation(character);
			}
			break;
		default:
			PooledStringBuilder sb =
					StringBuilderPool.getInstance().getStringBuilder();
			sb.append("Invalid player race: ");
			sb.append(character.getRace());
			sb.append(".");
			Exception ex = new Exception(sb.toString());
			sb.returnToPool();
			sb = null;
			throw ex;
		}
	}
	/**
	 * Sets the body level for a dwarf character based upon weight.
	 * @param character the {@link ChivSorcCharacter} being affected
	 */
	private void getDwarfBodyLevelForWeight(
			final ChivSorcCharacter character) {
		final int c = 100;
		int body = 0, roll = Diceroller.getInstance().rolldX(c);
		// set weight for body frame
		switch (character.getBaseframe()) {
		case ChivalrySorceryConstants.BODY_FRAME_00_VERY_LIGHT:
			roll = Diceroller.getInstance().rolldX(10) + 20;
			character.setBaseweight(character.getBaseweight() * (roll / 100f));
			break;
		case ChivalrySorceryConstants.BODY_FRAME_01_LIGHT:
			roll = Diceroller.getInstance().rolldX(10) + 10;
			character.setBaseweight(character.getBaseweight() * (roll / 100f));
			break;
		case ChivalrySorceryConstants.BODY_FRAME_03_LARGE:
			roll = Diceroller.getInstance().rolldX(10) + 10;
			character.setBaseweight(character.getBaseweight());
			break;
		case ChivalrySorceryConstants.BODY_FRAME_04_MASSIVE:
			roll = Diceroller.getInstance().rolldX(10) + 20;
			character.setBaseweight(character.getBaseweight() * (roll / 100f));
			break;
		}
		// set body level based upon weight
		if (character.getBaseweight() < 60) {
			body = 7;
		} else if (character.getBaseweight() < 70) {
			body = 8;
		} else if (character.getBaseweight() < 82) {
			body = 9;
		} else if (character.getBaseweight() < 91) {
			body = 10;
		} else if (character.getBaseweight() < 97) {
			body = 11;
		} else if (character.getBaseweight() < 105) {
			body = 12;
		} else if (character.getBaseweight() < 110) {
			body = 13;
		} else if (character.getBaseweight() < 115) {
			body = 14;
		} else if (character.getBaseweight() < 120) {
			body = 15;
		} else if (character.getBaseweight() < 125) {
			body = 16;
		} else if (character.getBaseweight() < 130) {
			body = 17;
		} else if (character.getBaseweight() < 140) {
			body = 18;
		} else if (character.getBaseweight() < 150) {
			body = 19;
		} else if (character.getBaseweight() < 160) {
			body = 20;
		} else {
			body = 21;
		}
		character.setBasebody(body);
	}
	/**
	 * Sets the body level for a haefling character based upon weight.
	 * @param character the {@link ChivSorcCharacter} being affected
	 */
	private void getHaeflingBodyLevelForWeight(
			final ChivSorcCharacter character) {
		final int c = 100;
		int body = 0, roll = Diceroller.getInstance().rolldX(c);
		// set weight for body frame
		switch (character.getBaseframe()) {
		case ChivalrySorceryConstants.BODY_FRAME_00_VERY_LIGHT:
			roll = Diceroller.getInstance().rolldX(10) + 20;
			character.setBaseweight(character.getBaseweight() * (roll / 100f));
			break;
		case ChivalrySorceryConstants.BODY_FRAME_01_LIGHT:
			roll = Diceroller.getInstance().rolldX(10) + 10;
			character.setBaseweight(character.getBaseweight() * (roll / 100f));
			break;
		case ChivalrySorceryConstants.BODY_FRAME_03_LARGE:
			roll = Diceroller.getInstance().rolldX(10) + 10;
			character.setBaseweight(character.getBaseweight());
			break;
		case ChivalrySorceryConstants.BODY_FRAME_04_MASSIVE:
			roll = Diceroller.getInstance().rolldX(10) + 20;
			character.setBaseweight(character.getBaseweight() * (roll / 100f));
			break;
		}
		// set body level based upon weight
		if (character.getBaseweight() < 45) {
			body = 5;
		} else if (character.getBaseweight() < 59) {
			body = 6;
		} else if (character.getBaseweight() < 72) {
			body = 7;
		} else if (character.getBaseweight() < 80) {
			body = 8;
		} else if (character.getBaseweight() < 92) {
			body = 9;
		} else if (character.getBaseweight() < 100) {
			body = 10;
		} else if (character.getBaseweight() < 105) {
			body = 11;
		} else if (character.getBaseweight() < 110) {
			body = 12;
		} else if (character.getBaseweight() < 120) {
			body = 13;
		} else if (character.getBaseweight() < 130) {
			body = 14;
		} else {
			body = 15;
		}
		character.setBasebody(body);
	}
	/**
	 * Sets the body level for a human character based upon weight.
	 * @param character the {@link ChivSorcCharacter} being affected
	 */
	private void setHumanBodyLevelForWeight(
			final ChivSorcCharacter character) {
		final int c = 100;
		int body = 0, roll = Diceroller.getInstance().rolldX(c);
		// set weight for body frame
		switch (character.getBaseframe()) {
		case ChivalrySorceryConstants.BODY_FRAME_00_VERY_LIGHT:
			roll = Diceroller.getInstance().rolldX(10) + 20;
			character.setBaseweight(character.getBaseweight() * (roll / 100f));
			break;
		case ChivalrySorceryConstants.BODY_FRAME_01_LIGHT:
			roll = Diceroller.getInstance().rolldX(10) + 10;
			character.setBaseweight(character.getBaseweight() * (roll / 100f));
			break;
		case ChivalrySorceryConstants.BODY_FRAME_03_LARGE:
			roll = Diceroller.getInstance().rolldX(10) + 10;
			character.setBaseweight(character.getBaseweight());
			break;
		case ChivalrySorceryConstants.BODY_FRAME_04_MASSIVE:
			roll = Diceroller.getInstance().rolldX(10) + 20;
			character.setBaseweight(character.getBaseweight() * (roll / 100f));
			break;
		}
		// set body level based upon weight
		body = (int) character.getBaseweight() / 10;
		if (character.getRace() == ChivalrySorceryConstants.PLAYER_RACE_01_WOOD_ELF
				|| character.getRace() == ChivalrySorceryConstants.PLAYER_RACE_02_HIGH_ELF) {
			if (character.getGender() == ChivalrySorceryConstants.GENDER_FEMALE) {
				body++;
			} else {
				body += 2;
			}
		}
		character.setBasebody(body);
	}
}
